package org.one.stone.soup.grfxML.plugin.system;

import org.one.stone.soup.grfxML.DataChildren;
import org.one.stone.soup.grfxML.DataNode;
import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.DataLinker;

public class DropAction extends SimplePlugin implements DropBuilder{

	private static int ARG_TARGET = 0;
	private DataChildren buildTarget;

/**
 * SuperString constructor comment.
 */
public DropAction(GrfxMLEngine engine){
	super(engine);

	buildTarget = new DataChildren(engine);
}
/**
 * initialize method comment.
 */
public void initialize()
{
}
/**
 * process method comment.
 */
public void process(){}
/**
 * register method comment.
 */
public void register(DataLinker store)
{
	buildTarget	=	grfxMLCaster.cast(buildTarget,getArg(buildTarget,ARG_TARGET,store));
}

/**
 * replace method comment.
 */
public void replace(org.one.stone.soup.mjdb.data.field.Field oldObj, org.one.stone.soup.mjdb.data.field.Field newObj)
{
	buildTarget		=	grfxMLCaster.replace(buildTarget,oldObj,newObj);
}



public void stop(){}

public void buildIn(DataChildren container,DataNode newNode)
{
	try{
		container.remove(newNode,this);

		newNode.getTranslation().getPosition().setValueX(0,this);
		newNode.getTranslation().getPosition().setValueY(0,this);
		buildTarget.add(newNode,this);

		newNode.getParent().getTranslation().setChanged();

		getEngine().getAPI().commit();
	}
	catch(Exception e){}
}

}
